package com.system.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcConnection {
    public static Connection connection=getConnection();
    static private String hostIp;
    static private String port;
    static private String dbName;
    static private String dbUser;
    static private String password;

    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            hostIp="127.0.0.1";
            port="3306";
            dbName="marketsystem";
            dbUser="root";
            password="123456";
        } catch (ClassNotFoundException e) {
            System.out.println("数据库包无法加载");
            e.printStackTrace();
        }
        String dbURL="jdbc:mysql://localhost:3306/marketsystem?useUnicode=true&characterEncoding=utf8&useSSL=true";

        try {
            return DriverManager.getConnection(dbURL,dbUser,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
